//
//  VisualCollectionViewCell.m
//  礼物
//
//  Created by dllo on 15/11/13.
//  Copyright © 2015年 liangsicheng. All rights reserved.
//

#import "VisualCollectionViewCell.h"

@implementation VisualCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self creataSubviews];
    }
    return  self;
}

- (void)creataSubviews
{
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    //图片
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height / 3 * 2)];
    //self.imageView.backgroundColor = [UIColor orangeColor];
    [self.contentView addSubview:self.imageView];
    
    //播放按钮
    self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.playButton.frame = CGRectMake(self.imageView.frame.size.width / 4 * 1.5, self.imageView.frame.size.height / 3 , self.imageView.frame.size.width / 8, self.imageView.frame.size.width / 8);
    self.playButton.center = self.imageView.center;//中心相等
    [self.playButton setBackgroundImage:[UIImage imageNamed:@"iconfont-bofang"] forState:UIControlStateNormal];
    [self.playButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.imageView addSubview:self.playButton];
    
    
    //标题
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.imageView.frame.size.height, self.imageView.frame.size.width - 10, (self.contentView.frame.size.height - self.imageView.frame.size.height) / 2)];
    //self.titleLabel.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:self.titleLabel];
    
    //灰线
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height + 1, self.contentView.frame.size.width, 1)];
    view.backgroundColor = RGBA(236, 235, 241, 1);
    [self.contentView addSubview:view];
    
    //类型
    self.categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height + 1, self.contentView.frame.size.width / 2, self.titleLabel.frame.size.height)];
    //self.categoryLabel.backgroundColor = [UIColor greenColor];
    [self.contentView addSubview:self.categoryLabel];
    
    //时长
    self.durationLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.categoryLabel.frame.origin.x + self.categoryLabel.frame.size.width, self.categoryLabel.frame.origin.y, self.categoryLabel.frame.size.width - 10, self.categoryLabel.frame.size.height)];
    //self.durationLabel.backgroundColor = [UIColor blueColor];
    [self.contentView addSubview:self.durationLabel];
}

- (void)buttonAction:(UIButton *)btn
{
    
}

- (void)setModel:(VisualModel *)model
{
    
    _model=model;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:_model.coverForDetail]];
    self.titleLabel.text = _model.title;
    self.titleLabel.textColor = [UIColor blackColor];
    self.titleLabel.textAlignment = NSTextAlignmentLeft;
    self.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:19];
    
    self.categoryLabel.text = [NSString stringWithFormat:@"类型: %@",_model.category];
    self.categoryLabel.textColor = [UIColor lightGrayColor];
    self.categoryLabel.textAlignment = NSTextAlignmentLeft;
    self.categoryLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
    
    NSString *string = [NSString stringWithFormat:@"%ld:",_model.duration / 60];
    NSString *string2 = [NSString stringWithFormat:@"%ld",_model.duration % 60];
    NSString *appendStr = [string stringByAppendingString:string2];
    self.durationLabel.text = [NSString stringWithFormat:@"时长: %@",appendStr];
    self.durationLabel.textColor = [UIColor lightGrayColor];
    self.durationLabel.textAlignment = NSTextAlignmentLeft;
    self.durationLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:17];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
